// Copyright [2020] <unknown>
#include <bits/stdc++.h>
using namespace std;
// #define ONLINE_JUDGE
#ifndef ONLINE_JUDGE
#define dbg(x...) { cerr << "\033[32;1m" << #x << " -> "; err(x); }
void err() { cerr << "\033[39;0m" << endl; }
template<typename T, typename... A>
void err(T a, A... x) { cerr << a << ' '; err(x...); }
#else
#define dbg(...)
#endif

#define sz(x) ((int)x.size())

typedef long long LL;

int t, n;
LL x, y;
LL ans;


void upt(LL xx) {
    LL yy = min((x-xx*2)/4, (y-xx*3));
    if (xx>=0 && yy>=0)
        ans = max(ans, xx+yy);
}
int main(int argc, char const *argv[]) {
    // code
    scanf("%d", &t);
    for (int kk=0; kk<t; ++kk) {
        scanf("%lld%lld", &x, &y);
        ans = max(min(x/2, y/3), min(x/4, y));
        LL xx = (4*y-x) / 10; upt(xx);
        xx = (4*y-x+9)/10;
        upt(xx);
        printf("%lld\n", ans);
    }
    return 0;
}
